package KwayMergeSort;
// Autumn 2012 TCSS343 Homework 3
// K-Way Mergesort

/**
 * A MergesortHeapNode has a key and an index that indicates which subarray that
 * key came from.
 * 
 * @author Donald Chinn
 * @author Daniel M. Zimmerman
 * @version October 2012
 */
@SuppressWarnings("rawtypes")
public class MergesortHeapNode implements Comparable
{
  /**
   * The data in the node.
   */
  private final int my_data;

  /**
   * The subarray the data came from.
   */
  private final int my_subarray;

  /**
   * Constructs a MergesortHeapNode with the specified data and subarray.
   * 
   * @param the_data The data to be stored in the node.
   * @param the_subarray The subarray (0 .. k-1) from k-way mergesort
   * the data came from.
   */
  public MergesortHeapNode(final int the_data, final int the_subarray)
  {
    my_data = the_data;
    my_subarray = the_subarray;
  }

  /**
   * @return The data in the node.
   */
  public int data()
  {
    return my_data;
  }

  /**
   * @return The subarray the data came from.
   */
  public int subarray()
  {
    return my_subarray;
  }

  /**
   * Compares this object to another for ordering.
   * 
   * @param the_other The other MergesortHeapNode object.
   * @return 0 if the two objects are equal; less than zero if this object is
   *         smaller; greater than zero if this object is larger.
   * @exception ClassCastException if the_other is not a MergesortHeapNode.
   */
  @Override
  public int compareTo(final Object the_other) throws ClassCastException
  {
    int result = 1;
    
    if (my_data < ((MergesortHeapNode) the_other).my_data)
    {
      result = -1;
    }
    else if (my_data == ((MergesortHeapNode) the_other).my_data)
    {
      result = 0;
    }

    return result;
  }
}
